<div class="portlet col-xs-12 padding0">
	<div class="portlet-title">
	<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
	<span>组织列表</span>
	<form class="form-inline pull-right" onsubmit="return false">
			<label for="orgKey">关键字</label> 
			<input type="text" id="orgKey" class="form-control" placeholder="要查询的关键字" />
			<label for="orgStatus">状态</label>
			<select class="form-control" id="orgStatus">
			<option value="-1">所有</option>
			<option value="0">正常</option>
			<option value="1">停用</option>
			</select>
		<button type="button" class="btn btn-xs btn-info" onclick="showOrgList()">查询</button>
		<button type="button" prid="createOrg" class="btn btn-info btn-xs" style="margin-right:10px" onclick="createOrg()">新增</button>
</form>
	</div>
	<div id="orgDataGrid" class="portlet-box"></div>
</div>

<script type="text/javascript">
	showOrgList();
	function showOrgList() {
		var operations = [ {"name" : "查看","callback" : "getOrg","width" :0.1}, 
		                   {"name" : "修改","callback" : "modifiyOrg"}, 
		                   {"name" : function(row) {
								if (row["状态"] == "正常") {
									return "禁用";
								} else {
									return "启用";
								}
							},
							"callback" : function(row) {
								if (row["状态"] == "正常") {
									return "disabledOrg";
								} else {
									return "enabledOrg";
								}
							}
		} ];
		//查询条件
		var conditions = [{"column":"orgkey","value":$("#orgKey").val().trim(),"rule":""},
		                  {"column":"status","value":$("#orgStatus").val(),"rule":""}];
		$("#orgDataGrid").fdatagrid({
			reportId : 'getOrg',
			condition : conditions,
			operation : operations,
			itemClick : getOrg
		});
	}
	var orgDialog = {windowId :"Random",popWidth :600,position : "center",src : "../org/org_dialog.html",	title : ""};
	function getOrg(i) {
		if (isNaN(i)) {
			em.OrgId = $(this).find("td:eq(0)").html();
		} else {
			em.OrgId = $('#orgDataGrid').find("tr:eq(" + (i + 1) + ")").find("td:eq(0)").html();
		}
		em.Operation = "show";
		orgDialog.title = "查看组织";
		Dialog = popWindowShow(orgDialog);
	}
	function modifiyOrg(i) {
		em.Operation = "modify";
		em.OrgId = $('#orgDataGrid').find("tr:eq(" + (i + 1) + ")").find("td:eq(0)").html();
		orgDialog.title = "修改组织";
		Dialog = popWindowShow(orgDialog);
	}

	function createOrg() {
		orgDialog.title = "新增组织";
		em.Operation = "create";
		Dialog = popWindowShow(orgDialog);
	}
	
	function enabledOrg(i) {
		em.OrgId = $('#orgDataGrid').find("tr:eq(" + (i + 1) + ")").find("td:eq(0)").html();
		var _orgName = $('#orgDataGrid').find("tr:eq(" + (i + 1) + ")").find("td:eq(1)").html();
		if (confirm("您确定要启用该组织？")) {
			callSvr("OrgManage/enabledOrg", {"OrgId" : em.OrgId,"orgName" : _orgName}, function(result) {
				if (result.err == 0) {
					toastr.success('组织已启用', '');
					$("#main").empty().load("../org/org.html");
				}
			});
		}
	}
	function disabledOrg(i) {
		em.OrgId = $('#orgDataGrid').find("tr:eq(" + (i + 1) + ")").find("td:eq(0)").html();
		var _orgName = $('#orgDataGrid').find("tr:eq(" + (i + 1) + ")").find("td:eq(1)").html();
		if (confirm("您确定要停用该组织？停用后相关账号都将禁用!")) {
			callSvr("OrgManage/disabledOrg", {"OrgId" : em.OrgId,"orgName" : _orgName}, function(result) {
				if (result.err == 0) {
					toastr.success('组织已停用', '');
					$("#main").empty().load("../org/org.html");
				}
			});
		}
	}
</script>
